package com.itheima.app.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.omg.DynamicAny._DynAnyFactoryStub;
import org.springframework.context.annotation.Configuration;

import java.sql.DatabaseMetaData;
import java.util.Date;

@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        Object created = getFieldValByName("created", metaObject);

        if (created == null) {

            setFieldValByName("created", new Date(), metaObject);
        }

        Object update = getFieldValByName("updated", metaObject);

        if (update == null) {

            setFieldValByName("updated", new Date(), metaObject);
        }
    }

    @Override
    public void updateFill(MetaObject metaObject) {

            setFieldValByName("updated", new Date(), metaObject);
    }
}
